package com.hoangkien.service;

import java.util.ArrayList;

import com.hoangkien.DAO.CreateDatabase;
import com.hoangkien.DAO.UserDAO;
import com.hoangkien.entity.UserEntity;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class UserService {
	private Context context;

	public UserService(Context context) {
		this.context = context;
	}
	
	public long insert_user(UserEntity userEntity){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		UserDAO userDAO = new UserDAO(db);
		long result = userDAO.insertUser(userEntity);
		db.close();
		createDb.close();
		return result;
	}
	public ArrayList<UserEntity> getAllUser(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		UserDAO userDAO = new UserDAO(db);
		ArrayList<UserEntity> list_author = new ArrayList<UserEntity>();
		list_author = userDAO.getAllUser();
		db.close();
		createDb.close();
		return list_author;
	}
	
	public long deleteUser(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		UserDAO userDAO = new UserDAO(db);
		long result = userDAO.deleteTableUser();
		db.close();
		createDb.close();
		return result;
	}
}
